package org.flashbrighton.as3bots.controllers
{
	import flash.display.Stage;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	
	import org.flashbrighton.as3bots.events.BotEvent;

	public class HouseBotController implements IBotController
	{
		private var _enginePower:Number = 0;
		private var _steeringPower:Number = 0;		
		
		
		public function HouseBotController()
		{
		}


		public function run():void
		{
		}
		
		
		public function notify(event:BotEvent):void
		{
		}
		
		
		public function getEnginePower():Number
		{
			return _enginePower;
		}
		
		
		public function getSteeringPower():Number
		{
			return _steeringPower;
		}
		
		
		public function enableKeys(stage:Stage):void
		{
			stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
 			stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
		}
		
		
		private function onKeyDown(k:KeyboardEvent):void
 		{ 	
 			switch (k.keyCode)
 			{
 				case Keyboard.UP:
 				_enginePower = 1.0;
 				break;
 				
 				case Keyboard.DOWN:
 				_enginePower = -1.0;
 				break;
 				
 				case Keyboard.LEFT:
 				_steeringPower = -1.0;
 				break;
 				
 				case Keyboard.RIGHT:
 				_steeringPower = 1.0;
 				break;
 			}
 		}
 		
 		
 		private function onKeyUp(k:KeyboardEvent):void
 		{ 			
 			if (k.keyCode == Keyboard.UP || k.keyCode == Keyboard.DOWN)
 			{
 				_enginePower = 0;
 			}
 			
 			if (k.keyCode == Keyboard.LEFT || k.keyCode == Keyboard.RIGHT)
 			{
 				_steeringPower = 0;
 			}			
 		}
 		
	}
}